package com.oa.s.data.sys.dao;

import java.util.List;
import java.util.Map;

import com.oa.s.data.common.dao.JdbcTemplateDao;
import com.oa.s.data.log.dao.EgLogDao;
import com.oa.s.data.sys.jdbc.SysSql;
import com.oa.s.engine.common.AbstractOaEngine;

@SuppressWarnings("unchecked")
public class SysDao extends JdbcTemplateDao {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Map<String, String> login(String loginName, String loginPass, String loginIp) {
		List<Map<String,String>> list=jdbcTemplate.queryForList(SysSql.getLoginInfo, new Object[]{loginName,loginPass});
		if(list.size()>0&&list!=null){
		this.runBack(new EgLogger(list.get(0).get("USER_ID"),list.get(0).get("ORG_ID"),loginIp));
		return list.get(0);
		}
		return null;
		// TODO Auto-generated method stub
	}
	class EgLogger extends AbstractOaEngine implements Runnable
	{
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		String userId = null;
		String orgId = null;
		String loginIp = null;
		
		public EgLogger(String userId, String orgId, String loginIp)
		{
			this.userId = userId;
			this.orgId = orgId;
			this.loginIp = loginIp;
		}		
		@Override
		public void run()
		{
			EgLogDao.addEgLog(userId,orgId,loginIp);
		}
	}
}
